package com.baomidou.springwind.controller.supply;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.kisso.annotation.Permission;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.springwind.controller.BaseController;
import com.baomidou.springwind.entity.NetworkDelivery;
import com.baomidou.springwind.entity.NetworkSupply;
import com.baomidou.springwind.entity.OrderData;
import com.baomidou.springwind.entity.SysArea;
import com.baomidou.springwind.mapper.NetworkDeliveryDao;
import com.baomidou.springwind.mapper.NetworkSupplyDao;
import com.baomidou.springwind.mapper.OrderDataDao;
import com.baomidou.springwind.mapper.SysAreaDao;
import com.baomidou.springwind.pojo.SiteCoverBuilder;
import com.baomidou.springwind.pojo.SiteSelection;
import com.baomidou.springwind.pojo.SiteSelectionBuilder;
import com.baomidou.springwind.service.NetworkSupplyService;
import com.baomidou.springwind.service.OrderDataService;
import com.baomidou.springwind.utils.CityUtil;
import com.baomidou.springwind.utils.ParamMap;
import com.baomidou.springwind.utils.ZvalueUtil;
import org.aspectj.weaver.patterns.HasMemberTypePattern;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 总体情况
 * </p>
 *
 * @Author demo
 * @Date 2017-10-7
 */
@Controller
@RequestMapping("/network/supply")
public class OverallController extends BaseController {

    @Autowired
    private NetworkDeliveryDao networkDeliveryDao;
    @Autowired
    private OrderDataDao orderDataDao;
    @Autowired
    private OrderDataService orderDataService;
    @Autowired
    private SysAreaDao sysAreaDao;

    private DecimalFormat df = new DecimalFormat("###,##0.00");

    /**
     * 客户分析主界面
     */
    @RequestMapping("/overall")
    @Permission("1001")
    public String customGroup(Model model) {
        return pjaxPath("/lpp/network/supply/overall/main", model);
    }

    /**
     * 客户分析主界面
     */
    @RequestMapping("/overall_new")
    @Permission("1001")
    public String overall_new(Model model) {
        return pjaxPath("/lpp/network/supply/overall/main_new", model);
    }

    /**
     * 获取展示数据
     */
    @ResponseBody
    @RequestMapping("/overall/getData")
    @Permission("1001")
    public String getData() {
        ParamMap<String, Object> pm = getParameterMap();
        EntityWrapper<NetworkDelivery> wrapper1 = new EntityWrapper<NetworkDelivery>();
        wrapper1.eq("batch_id", getProjectId());
        wrapper1.eq("operator_id",getCurrentUserId());
        List<NetworkDelivery> deliveryList = networkDeliveryDao.selectList(wrapper1);
        if(deliveryList.size()==0){
            String message="数据没有上传，请上传数据";
            return callbackFail(message);
        }
        JSONObject ret = calc(pm, deliveryList);
        EntityWrapper<OrderData> wrapper2 = new EntityWrapper<OrderData>();
        wrapper2.eq("batch_id", getProjectId());
        List<OrderData> orderDataList = orderDataDao.selectList(wrapper2);
        Map<String, Object> pm1 = getParameterMap();
        pm1.put("batchId",getProjectId());
        List<Map<String, Object>> inventoryCostList = orderDataDao.select1(pm1);
        List<Map<String, Object>> orderSuceess1=orderDataDao.selectOrderSuceess(pm1);
        if(orderSuceess1.size()==0){
            String message="数据的时间有问题，请检查时间";
            return callbackFail(message);
        }
        List<Map<String, Object>> orderSuceess2=orderDataDao.selectDeliveryReliabilityCounts(pm1);
        JSONObject ret1 = bars(pm,deliveryList,orderDataList,inventoryCostList,orderSuceess1,orderSuceess2);
        ret.putAll(ret1);
        return callbackSuccess(ret);
    }

    /**
     * 获取展示数据
     */
    @ResponseBody
    @RequestMapping("/overall/getDataNew")
    @Permission("1001")
    public String getDataNew() {
        ParamMap<String, Object> pm = getParameterMap();
        EntityWrapper<NetworkDelivery> wrapper = new EntityWrapper<NetworkDelivery>();
        wrapper.eq("batch_id", getProjectId());
        List<NetworkDelivery> networkDeliveries = networkDeliveryDao.selectList(wrapper);
        if(networkDeliveries.size()==0){
            String message="查询数据异常";
            return callbackFail(message);
        }
        List<NetworkDelivery> firstDeliveryList = new ArrayList<NetworkDelivery>();
        List<NetworkDelivery> secondDeliveryList = new ArrayList<NetworkDelivery>();
        for (NetworkDelivery delivery : networkDeliveries) {
            if (delivery.getType() == 1) {
                firstDeliveryList.add(delivery);
            }
            if(delivery.getType() == 2) {
                secondDeliveryList.add(delivery);
            }
        }
        SiteSelectionBuilder builder = new SiteSelectionBuilder(firstDeliveryList, secondDeliveryList);
        List<SiteSelection> siteSelectionList = builder.build();
        SiteCoverBuilder builder1 = new SiteCoverBuilder(siteSelectionList, secondDeliveryList);
        Map<SiteSelection, List<SiteSelection>> map = builder1.build();
        List<NetworkDelivery> deliveryList = new ArrayList<NetworkDelivery>();
        Long id = 0l;
        for (Map.Entry<SiteSelection, List<SiteSelection>> entry : map.entrySet()) {
            NetworkDelivery delivery = SiteSelection.transform(entry.getKey());
            delivery.setId(id);
            delivery.setType(1);
            deliveryList.add(delivery);
            for (SiteSelection child : entry.getValue()) {
                delivery = SiteSelection.transform(child);
                delivery.setType(2);
                delivery.setpId(id);
                deliveryList.add(delivery);
            }
            id++;
        }
        JSONObject ret = calc(pm, deliveryList);
        JSONObject ret1 = null;
        ret1=bars1(pm,map);
        if (ret1.get("time")!=null){
            return callbackFail(ret1.get("time").toString());
        }
        ret.putAll(ret1);
        return callbackSuccess(ret);
    }

    private JSONObject calc(ParamMap<String, Object> pm, List<NetworkDelivery> deliveryList) {
        //拆分一级、二级
        List<NetworkDelivery> firstDeliveryList = new ArrayList<NetworkDelivery>();
        List<Double> distanceList = new ArrayList<Double>();
        List<Double> orderList = new ArrayList<Double>();
        List<Double> costList = new ArrayList<Double>();
        List<Integer> vehicleList = new ArrayList<Integer>();
        double storeUnitPrice = pm.getDouble("storeUnitPrice");
        double area = pm.getDouble("area");
        for (NetworkDelivery delivery : deliveryList) {
            if (delivery.getType() == 1) {
                firstDeliveryList.add(delivery);
                distanceList.add(calcDistance(delivery, deliveryList));
                orderList.add(calcOrder(delivery, deliveryList));
                costList.add(calcCost(delivery, deliveryList,pm));
                vehicleList.add(calcVehicle(delivery, deliveryList,pm) );
            }
        }
        JSONArray classify = new JSONArray();
        JSONObject data;
        double totalOrder = 0d;
        double totalDistance = 0d;
        double totalCost = 0d;
        double totalVehicle = 0d;
        double renta = storeUnitPrice * area * 30;
        for (int i = 0; i < firstDeliveryList.size(); i++) {
            data = new JSONObject();
            NetworkDelivery delivery = firstDeliveryList.get(i);
            double distance = distanceList.get(i);
            data.put("name", delivery.getName());
            data.put("coordinateX", delivery.getCoordinateX());
            data.put("coordinateY", delivery.getCoordinateY());
            data.put("order", orderList.get(i));
            data.put("distance", distance);
            data.put("cost", costList.get(i));
            data.put("vehicle", vehicleList.get(i));
            totalOrder += orderList.get(i).doubleValue();
            totalDistance += distance;
            totalCost +=  costList.get(i);
            totalVehicle += vehicleList.get(i);
            classify.add(data);
        }
        totalCost += renta;
        JSONObject ret = new JSONObject();
        ret.put("data", classify);
        ret.put("totalOrder", df.format(totalOrder));
        ret.put("totalDistance", df.format(totalDistance));
        ret.put("totalCost", df.format(totalCost));
        ret.put("totalVehicle", totalVehicle);
        ret.put("renta", df.format(renta));
        return ret;
    }
    public JSONObject bars(Map<String, Object> pm,List<NetworkDelivery> d1,List<OrderData> orderDataList,List<Map<String, Object>> inventoryCostList,List<Map<String, Object>> orderSuceess1,List<Map<String, Object>> orderSuceess2){
        JSONObject ret = new JSONObject();
        JSONArray array1=new JSONArray();
        JSONArray array2=new JSONArray();
        JSONArray array3=new JSONArray();
        JSONArray array4=new JSONArray();
        JSONArray array5=new JSONArray();
        List<NetworkDelivery> deliveryList=new ArrayList<NetworkDelivery>();
        for (int i=0;i<d1.size();i++){
            if (d1.get(i).getType()==1){
                deliveryList.add(d1.get(i));
            }
        }
        for (int i=0;i<deliveryList.size();i++){
            array1.add(deliveryList.get(i).getName());
            List<Map<String, Object>> inventoryCostList2=new ArrayList<Map<String, Object>>();
            List<OrderData> orderDataList1=new ArrayList<OrderData>();
            long id=deliveryList.get(i).getLnglatId();
            for (Map<String, Object> map:inventoryCostList){
                if (Long.valueOf(map.get("branchId").toString())==id){
                    inventoryCostList2.add(map);
                }
            }
            for (int j=0;j<orderDataList.size();j++){
                if(id==orderDataList.get(j).getBranchId()) {
                    orderDataList1.add(orderDataList.get(j));
                }
            }
            HashMap<String,Integer> hashMap=moneyLevel(pm,orderDataList1,inventoryCostList2);
            array2.add(hashMap.get("moneyLevel"));
            array3.add(hashMap.get("avgInventory"));
        }

        for (int i=0;i<deliveryList.size();i++){
            List<Map<String, Object>> s1=new ArrayList<Map<String, Object>>();
            List<Map<String, Object>> s2=new ArrayList<Map<String, Object>>();
            long id=deliveryList.get(i).getLnglatId();
            for (Map<String, Object> map:orderSuceess1){
                if (Long.valueOf(map.get("branchId").toString())==id){
                    s1.add(map);
                }
            }
            for (Map<String, Object> map:orderSuceess2){
                if (Long.valueOf(map.get("branchId").toString())==id){
                    s2.add(map);
                }
            }
            array5.add(completionOrders(s1,s2));
        }

        ret.put("x1",array1);
        ret.put("x2",array2);//订货周期内库存商品占用资金水平
        ret.put("x3",array3);//订货周期内的平均库存
        ret.put("x4",array1);
        ret.put("x5",array5);//各一级配送中心平均订单完成率分布
        return ret;
    }
    public double completionOrders(List<Map<String, Object>> s1,List<Map<String, Object>> s2){
        double double1=0;
        for (Map<String, Object> map1:s1){
            for (Map<String, Object> map2:s2){
                if (map1.get("delivery").equals(map2.get("delivery"))){
                    double1=double1+Double.valueOf(map1.get("secondCounts").toString())/Double.valueOf(map2.get("secondCounts").toString());
                }
            }
        }
        double completionOrders=double1/s2.size();
        return completionOrders;
    }
    public double completionOrders1(List<SiteSelection> list){
        List<Long> stringList=new ArrayList<Long>();
        for(int i=0;i<list.size();i++){
            stringList.add(list.get(i).getLnglatId());
        }
        Map<String, Object> pm = getParameterMap();
        pm.put("delivery",stringList);
        pm.put("batch_id",getProjectId());
        List<Map<String, Object>> orderSuceess=orderDataDao.selectOrderSuceess1(pm);
        List<Map<String, Object>> orderSuceessCounts=orderDataDao.selectDeliveryReliabilityCounts1(pm);
        double double1=0;
        for (int i=0;i<orderSuceess.size();i++){
            double1=double1+Double.valueOf(orderSuceess.get(i).get("secondCounts").toString())/Double.valueOf(orderSuceessCounts.get(i).get("secondCounts").toString());
        }
        double completionOrders=double1/orderSuceessCounts.size();
        return completionOrders;
    }
    public JSONObject bars1(ParamMap<String, Object> pm,Map<SiteSelection, List<SiteSelection>> map){
        //创建JSON用于view层
        JSONObject ret = new JSONObject();
        JSONArray array1=new JSONArray();
        JSONArray array2=new JSONArray();
        JSONArray array3=new JSONArray();
        JSONArray array4=new JSONArray();
        JSONArray array5=new JSONArray();
        //batch_id的所有order数据
        EntityWrapper<OrderData> wrapper = new EntityWrapper<OrderData>();
        wrapper.eq("batch_id",getProjectId());
        List<OrderData> order1 = orderDataService.selectList(wrapper);
        //一级配送中心循环
        for (Map.Entry<SiteSelection, List<SiteSelection>> entry:map.entrySet()){
            List<Long> stringList=new ArrayList<Long>();
            //一级配送下面的二级配送中心
            for(int i=0;i<entry.getValue().size();i++){
                stringList.add(entry.getValue().get(i).getLnglatId());
            }
            //几个2级中心的所有order数据group by配车制单日期
            Map<String,Object> pm1=new HashMap<String,Object>();
            pm1.put("delivery",stringList);
            pm1.put("batchId",getProjectId());
            List<Map<String, Object>> s2 = orderDataDao.select2(pm1);
            //生成s1数据，和总的需求量simulateDemandSum
            List<SiteSelection> selectionList=entry.getValue();
            SiteSelection s0=entry.getKey();
            double simulateDemandSum=0;
            List<OrderData> s1=new ArrayList<OrderData>();
            for(int i=0;i<selectionList.size();i++){
                for (int j=0;j<order1.size();j++){
                    if (selectionList.get(i).getLnglatId().equals(order1.get(j).getDeliveryId())){
                        s1.add(order1.get(j));
                    }
                }
                simulateDemandSum=simulateDemandSum+Double.valueOf(selectionList.get(i).getOrder().toString());
            }
            array1.add(entry.getKey().getName());
            //通过moneyLevel1方法，获取数据
            try{
                HashMap<String,Integer> hashMap=moneyLevel1(s0,s1,s2,pm,simulateDemandSum);
                array2.add(hashMap.get("moneyLevel"));
                array3.add(hashMap.get("avgInventory"));
            }catch (Exception e){
                String message="上传数据不完整，请检查数据";
                ret.put("time",message);
                return ret;
            }
        }
        ret.put("x1",array1);
        ret.put("x2",array2);//订货周期内库存商品占用资金水平
        ret.put("x3",array3);//订货周期内的平均库存
        ret.put("x4",array4);
        ret.put("x5",array5);//各一级配送中心平均订单完成率分布
        return ret;
    }
    /**
     * 计算距离
     */
    private double calcDistance(NetworkDelivery first, List<NetworkDelivery> deliveryList) {
        double distance = 0d;
        for (NetworkDelivery second : deliveryList) {
            if (first.getId().equals(second.getpId())) {
                distance += CityUtil.getDistance(first.getCoordinateX().doubleValue(), first.getCoordinateY().doubleValue(),
                        second.getCoordinateX().doubleValue(), second.getCoordinateY().doubleValue());
            }
        }
        return distance;
    }

    /**
     * 计算总订单量
     */
    private double calcOrder(NetworkDelivery first, List<NetworkDelivery> deliveryList) {
        double order = 0d;
        for (NetworkDelivery second : deliveryList) {
            if (first.getId().equals(second.getpId())) {
                order += second.getOrderQuantity().doubleValue();
            }
        }
        return order;
    }
    /**
     * 计算总订单量
     */
    private int calcVehicle(NetworkDelivery first, List<NetworkDelivery> deliveryList,ParamMap<String,Object> pm) {
        double load = pm.getDouble("load");
        double volume = pm.getDouble("volume");
        double months=pm.getDouble("months");
        int vehicle = 0;
        for (NetworkDelivery second : deliveryList) {
            if (first.getId().equals(second.getpId())) {
                vehicle += (int) Math.ceil(second.getOrderQuantity().doubleValue() * volume / load / 30/months);
            }
        }
        return vehicle;
    }

    /**
     * 计算总订单量
     */
    private double calcCost(NetworkDelivery first, List<NetworkDelivery> deliveryList,ParamMap<String, Object> pm) {
        double unitPrice = pm.getDouble("unitPrice");
        double volume = pm.getDouble("volume");
        double load = pm.getDouble("load");
        double otherExpenses = pm.getDouble("otherExpenses");
        double months=pm.getDouble("months");
        double cost = 0d;
        for (NetworkDelivery second : deliveryList) {
            if (first.getId().equals(second.getpId())) {
                double distance =CityUtil.getDistance(first.getCoordinateX().doubleValue(), first.getCoordinateY().doubleValue(),
                        second.getCoordinateX().doubleValue(), second.getCoordinateY().doubleValue());
              int vehicle =   (int) Math.ceil(second.getOrderQuantity().doubleValue() * volume / load / 30/months);
                cost += unitPrice * vehicle * distance + otherExpenses;
            }
        }
        return cost;
    }
    //订货周期内库存商品占用资金水平
    public HashMap<String,Integer> moneyLevel(Map<String, Object> pm,List<OrderData> orderDataLists,List<Map<String, Object>> inventoryCostList2){
        double price=Double.valueOf(pm.get("goodsPrice").toString());
        int delayedDays=0;
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//创建日期转换对象HH:mm:ss为时分秒，年月日为yyyy-MM-dd
        List<Long> list=new ArrayList<Long>();
        Long advanceTimeSum=0L;
        List<OrderData> orderDataList = null;
        int demandSum=0;
        for (int i=0;i<orderDataLists.size();i++){
                demandSum=demandSum+orderDataLists.get(i).getOrderQuantity();
                try {
                    Date carArrive= orderDataLists.get(i).getCarArrive();
                    Date promiseArrival= orderDataLists.get(i).getPromiseArrival();
                    Date preparationCar= orderDataLists.get(i).getPreparationCar();
                    if (carArrive.getTime()<promiseArrival.getTime()) {
                        delayedDays++;
                    }
                    long diff=carArrive.getTime()-preparationCar.getTime();
                    long days=diff/(1000*60*60*24);
                    list.add(days);
                    advanceTimeSum=advanceTimeSum+days;
                }catch (Exception e){
                    System.out.println("时间有NULL的");
                }
        }
        //服务水平
        DecimalFormat decimalFormat= new DecimalFormat("######0.00");
        double serviceLevel=((double)delayedDays)/((double) orderDataLists.size());
        String serviceLevelString=decimalFormat.format(serviceLevel);
        //计算提前期的标准差
        double advanceAvg=((double)advanceTimeSum)/((double) orderDataLists.size());
        double advanceStandard=0;
        for (int i=0;i<list.size();i++){
            advanceStandard=advanceStandard+(list.get(i)-advanceAvg)*(list.get(i)-advanceAvg);
        }
        double demadAvg=demandSum/inventoryCostList2.size();
        //计算的日需求量标准差
        double demadStandard=0;
        for (int i=0;i<inventoryCostList2.size();i++){
            demadStandard=demadStandard+(Integer.valueOf(inventoryCostList2.get(i).get("ordersum").toString())-demadAvg)*(Integer.valueOf(inventoryCostList2.get(i).get("ordersum").toString())-demadAvg);
        }
        double z=ZvalueUtil.getZ(serviceLevelString);
        double value= z*Math.sqrt(demadStandard/inventoryCostList2.size()*advanceAvg+advanceStandard/list.size()*demadAvg*demadAvg);

        //一级配送中心再订货点
        double orderPort=value+demadAvg*advanceAvg;
        //订货周期内的周转库存
        double turnoverInventory;
        double dateInterval=0;
        for (int i=1;i<=inventoryCostList2.size();i++){
            try{
                Date preparationCar1=df.parse(inventoryCostList2.get(i-1).get("preparationCar").toString());
                Date preparationCar2=df.parse(inventoryCostList2.get(i).get("preparationCar").toString());
                long diff=preparationCar2.getTime()-preparationCar1.getTime();
                long days=diff/(1000*60*60*24);
                dateInterval=dateInterval+days;
            }catch (Exception e){
            }
        }
        double dateIntervalAvg=dateInterval/inventoryCostList2.size();
        turnoverInventory=dateIntervalAvg*demadAvg;
        //订货周期内的最大库存
        double maxInventory=turnoverInventory+value;
        //订货周期内的平均库存
        double avgInventory=value+turnoverInventory/2;
        //订货周期内库存商品占用资金水平
        double moneyLevel=avgInventory*price;
        //一级配送中心1个月的平均库存
        double months=30;
        double monthAvgInventory=(months/dateIntervalAvg)*avgInventory;
        HashMap<String,Integer> hashMap=new HashMap<String, Integer>();
        hashMap.put("moneyLevel",1+(int)moneyLevel);
        hashMap.put("avgInventory",1+(int)avgInventory);
        return hashMap;
    }
    public HashMap<String,Integer> moneyLevel1(SiteSelection map,List<OrderData> inventoryCostAfterList,List<Map<String, Object>> inventoryCostList2,ParamMap<String, Object> pms,double simulateDemandSum){
        //对pm进行处理
        String prices=pms.get("prize").toString();
        String dealTime=pms.get("dealTime").toString();
        String holdCost=pms.get("holdCost").toString();
        String orderCost=pms.get("orderCost").toString();
        String month=pms.get("months").toString();
        double price=Double.valueOf(prices);
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");//创建日期转换对象HH:mm:ss为时分秒，年月日为yyyy-MM-dd
        List<Long> list=new ArrayList<Long>();
        Long advanceTimeSum=0L;
        //处理得到服务水平 提前期 所需要的数据
        for (int i=0;i<inventoryCostAfterList.size();i++){
            int days=node1ToNode2Distance(Double.valueOf(map.getCoordinateY().toString()),Double.valueOf(map.getCoordinateX().toString()),Double.valueOf(inventoryCostAfterList.get(i).getFactoryLat()),Double.valueOf(inventoryCostAfterList.get(i).getFactoryLng()))+Integer.valueOf(dealTime);
            list.add(Long.valueOf(String.valueOf(days)));
            advanceTimeSum=advanceTimeSum+days;
        }
        //服务水平
        String serviceLevelString=pms.get("costomService").toString();
        //计算提前期的标准差
        double advanceAvg=((double)advanceTimeSum)/((double)inventoryCostAfterList.size());
        double advanceStandard=0;
        for (int i=0;i<list.size();i++){
            advanceStandard=advanceStandard+(list.get(i)-advanceAvg)*(list.get(i)-advanceAvg);
        }
        int demandSum=0;
        for (int i=0;i<inventoryCostList2.size();i++){
            demandSum=demandSum+Integer.valueOf(inventoryCostList2.get(i).get("ordersum").toString());
        }
        double demadAvg=demandSum/inventoryCostList2.size();
        //计算的日需求量标准差
        double demadStandard=0;
        for (int i=0;i<inventoryCostList2.size();i++){
            demadStandard=demadStandard+(Integer.valueOf(inventoryCostList2.get(i).get("ordersum").toString())-demadAvg)*(Integer.valueOf(inventoryCostList2.get(i).get("ordersum").toString())-demadAvg);
        }
        double z=ZvalueUtil.getZ(serviceLevelString);
        double value= z*Math.sqrt(demadStandard/inventoryCostList2.size()*advanceAvg+advanceStandard/list.size()*demadAvg*demadAvg);
        //一级配送中心再订货点
        double orderPort=value+demadAvg*advanceAvg;
        // 经济订货批量(EOQ)
        double eoq=Math.sqrt(2*simulateDemandSum*Integer.valueOf(orderCost)/Integer.valueOf(holdCost));
        //订货周期内的周转库存
        double turnoverInventory;
        double dateInterval=0;
        for (int i=1;i<=inventoryCostList2.size();i++){
            try{
                Date preparationCar1=df.parse(inventoryCostList2.get(i-1).get("preparationCar").toString());
                Date preparationCar2=df.parse(inventoryCostList2.get(i).get("preparationCar").toString());
                long diff=preparationCar2.getTime()-preparationCar1.getTime();
                long days=diff/(1000*60*60*24);
                dateInterval=dateInterval+days;
            }catch (Exception e){
            }
        }
        double dateIntervalAvg=dateInterval/inventoryCostList2.size();
        turnoverInventory=demadAvg*(30*eoq*Integer.valueOf(month)/simulateDemandSum);
        //订货周期内的最大库存
        double maxInventory=turnoverInventory+value;
        //订货周期内的平均库存
        double avgInventory=value+turnoverInventory/2;
        //订货周期内库存商品占用资金水平
        double moneyLevel=avgInventory*price;
        //一级配送中心1个月的平均库存
        double months=30;
        double monthAvgInventory=(months/dateIntervalAvg)*avgInventory;
        HashMap<String,Integer> hashMap=new HashMap<String, Integer>();
        hashMap.put("moneyLevel",1+(int)moneyLevel);
        hashMap.put("avgInventory",1+(int)avgInventory);
        return hashMap;
    }
    public  int node1ToNode2Distance(double wd1,double jd1,double wd2,double jd2)
    {
        double x,y,out;
        double PI=3.14159265;
        double R=6.371229*1e6;

        x=(jd2-jd1)*PI*R*Math.cos( ((wd1+wd2)/2) *PI/180)/180;
        y=(wd2-wd1)*PI*R/180;
        out=Math.hypot(x,y);
        int time=1+(int)(out/1000)/60/24;
        return time;
    }
    @RequestMapping("/overall/bar11")
    @Permission("1001")
    public String bar11(Long batchId,Model model) {
        model.addAttribute("batchId",batchId);
        return "/lpp/network/supply/overall/bar1";
    }
    @RequestMapping("/overall/bar21")
    @Permission("1001")
    public String bar21(Long batchId,Model model) {
        model.addAttribute("batchId",batchId);
        return "/lpp/network/supply/overall/bar2";
    }
 }
